package base.java8;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * 异常处理的新写法
 *
 * @author 王霄
 * @date 2021/5/1 18:51
 */
public class ExceptionDemo {

    public static void main(String[] args) {
        read1();
        read2();
    }

    public static void read1() {
        //java8
        try (var reader = new BufferedReader(new InputStreamReader(System.in))) {
            while (reader.markSupported()) {
                System.out.println(reader.readLine());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void read2() {
        //java9之后
        var reader = new BufferedReader(new InputStreamReader(System.in));
        try (reader) {
            while (reader.markSupported()) {
                System.out.println(reader.readLine());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
